package com.chance.cc.crawler.development.bootstrap.qimai;

import com.chance.cc.crawler.core.CrawlerEnum;
import com.chance.cc.crawler.core.downloader.HttpConfig;
import com.chance.cc.crawler.core.downloader.proxy.Proxy;
import com.chance.cc.crawler.core.filter.FilterUtils;
import com.chance.cc.crawler.core.record.CrawlerRequestRecord;
import com.chance.cc.crawler.development.controller.DevCrawlerController;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName song
 * @Description TODO
 * @Author ding
 * @Date 2021/9/6 14:56
 * @Version 1.0
 **/
public class QimaiStart {
    private static final String domain = "qimai";
    private static final Map<String,String> headMap = new HashMap<>();
    private static final Map<String,String> cookieMap = new HashMap<>();
    private static Proxy proxy = new Proxy();
    static {
        //代理配置
        //HL89Q19E86E2987D
        //71F33D94CE5F7BF2
        proxy.setHost("http-dyn.abuyun.com");
        proxy.setPort(9020);
        proxy.setUsername("HL89Q19E86E2987D");
        proxy.setPassword("71F33D94CE5F7BF2");
    }
    public static void main(String[] args) {
        CrawlerRequestRecord record  = appStore();//苹果
        //CrawlerRequestRecord record  = oppo();
        DevCrawlerController.builder()
                .triggerInfo(domain,domain,System.currentTimeMillis(),domain)
                .crawlerRequestQueue(DevCrawlerController.devRequestQueue(domain))
                .consoleResultPipeline("kafka")
                .fileResultPipeline("kafka","F:\\chance_log\\sohu\\article\\data.log",false)
                .requestRecord(record)
                //.supportRecord(keyRecord)
                .build("com.chance.cc.crawler.development.scripts.qimai")
                .start();
    }

    public static CrawlerRequestRecord appStore(){
        String site = "appStore";
        String url = "https://www.qimai.cn/app/comment/appid/1570277888/country/cn";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpConfig(HttpConfig.me(domain))
                .httpUrl(url)
                .recordKey(url)
                .releaseTime(System.currentTimeMillis())
                .proxy(proxy)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*1,null))
                .needParsed(true)
                .needWashed(false)
                .build();
        record.getHttpRequest().setHeaders(headMap);
        record.getHttpRequest().setCookies(cookieMap);
        record.tagsCreator().bizTags().addDomain(domain);
        record.tagsCreator().bizTags().addSite(site);
        return record;
    }

    public static CrawlerRequestRecord oppo(){
        String site = "oppo";
        String url = "https://www.qimai.cn/andapp/comment/appid/7797760/market/9";
        CrawlerRequestRecord record = CrawlerRequestRecord.builder()
                .startPageRequest(domain, CrawlerEnum.CrawlerRequestType.turnPage)
                .domain(domain)
                .httpConfig(HttpConfig.me(domain))
                .httpUrl(url)
                .recordKey(url)
                .releaseTime(System.currentTimeMillis())
                .proxy(proxy)
                .filter(CrawlerEnum.CrawlerRecordFilter.dateRange)
                .addFilterInfo(FilterUtils.dateRangeFilterInfo(24*30,null))
                .needParsed(true)
                .needWashed(false)
                .build();
        record.tagsCreator().bizTags().addDomain(domain);
        record.tagsCreator().bizTags().addSite(site);
        return record;

    }


    static {
      /*  headMap.put("Date","Mon, 06 Sep 2021 06:15:00 GMT");
        headMap.put("Content-Type","application/json; charset=utf-8");
        headMap.put("Transfer-Encoding","chunked");
        headMap.put("Connection","keep-alive");
        headMap.put("Set-Cookie","tgw_l7_route=29ef178f2e0a875a4327cbfe5fbcff7e; Expires=Mon, 06-Sep-2021 06:15:30 GMT; Path=/");
        headMap.put("Set-Cookie","PHPSESSID=3tnbk0khaac5iiu96m7cbdi9a7; path=/; domain=qimai.cn");
        headMap.put("Server","openresty/1.15.8.3");
        headMap.put("X-Powered-By","PHP/7.2.33");
        headMap.put("Access-Control-Expose-Headers","Server-U, Server-Time");
        headMap.put("Access-Control-Allow-Credentials","true");
        headMap.put("Access-Control-Allow-Origin","https://www.qimai.cn");
        headMap.put("Expires","Thu, 19 Nov 1981 08:52:00 GMT");
        headMap.put("Cache-Control","no-store, no-cache, must-revalidate");
        headMap.put("Pragma","no-cache");
        headMap.put("Server-Time","1630908900000");
        headMap.put("Content-Encoding","gzip");
        cookieMap.put("synct", String.valueOf(new StringBuffer(String.valueOf(System.currentTimeMillis())).insert(10,".")));
        cookieMap.put("PHPSESSID","3tnbk0khaac5iiu96m7cbdi9a7");*/
    }

}
